package com.sims.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.sims.bean.CourseInfo;
import com.sims.bean.Teacher;
import com.sims.dao.IClassDAO;
import com.sims.dao.ICourseInfoDAO;
import com.sims.dao.ITeacherDAO;
import com.sims.util.Constant;
import com.sims.util.HttpSessionUtil;

public class ClassService {
	@Autowired
	private IClassDAO classDAO;
	@Autowired
	private ITeacherDAO teacherDAO;
	@Autowired
	private ICourseInfoDAO courseInfoDAO;
	
	/** 学生找出所在班级；老师找出所教班级、所任班主任的班级
	 * @param classList
	 * @return
	 */
	public Map<String, String> findClass(List<com.sims.bean.Class> classList) {
		Map<String, String> result = new HashMap<String, String>();
		
		Integer id = HttpSessionUtil.getUserId();
		
		if (HttpSessionUtil.getUserType() == Constant.TEACHER) {
			if (HttpSessionUtil.getUserClassId() != null) {
				com.sims.bean.Class temp = classDAO.findById(HttpSessionUtil
						.getUserClassId());
				classList.add(temp);
			}
			List<CourseInfo> ciList = courseInfoDAO.findByTid(id);
			for (CourseInfo ci : ciList) {
				com.sims.bean.Class temp = classDAO.findById(ci.getCid());
				classList.add(temp);
			}
		}
		else if (HttpSessionUtil.getUserType() == Constant.STUDENT){
			com.sims.bean.Class temp = classDAO.findById(HttpSessionUtil
					.getUserClassId());
			classList.add(temp);
		}
		
		result.put(Constant.SUCCESS, null);
		return result;
	}
}
